import {defHttp} from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/entrust/labEntrust/list',
  save='/entrust/labEntrust/add',
  edit='/entrust/labEntrust/edit',
  deleteOne = '/entrust/labEntrust/delete',
  deleteBatch = '/entrust/labEntrust/deleteBatch',
  importExcel = '/entrust/labEntrust/importExcel',
  exportXls = '/entrust/labEntrust/exportXls',
  labSampleList = '/entrust/labEntrust/queryLabSampleByMainId',
  sampleList = '/sample/labSample/sampleList',
  sampleOut = '/sample/labSample/sampleOut',
  sampleBack = '/sample/labSample/sampleBack',
  labItemsLists  = '/entrust/labEntrust/queryLabItemsByMainId',
  entrutSamList = '/sample/labEntrustSample/list',
  samExportXls = '/sample/labEntrustSample/exportXls',
  entrutSampleList = '/sample/labEntrustSample/sampleList',
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;

/**
 * 导出api
 * @param params
 */
export const getSamExportXls = Api.samExportXls;

/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 子表单查询接口
 * @param params
 */
export const queryLabSample = Api.labSampleList
/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
  defHttp.get({url: Api.list, params});


  /**
 * 列表接口
 * @param params
 */
export const entrutSamList = (params) =>
defHttp.get({url: Api.entrutSamList, params});


/**
 * 删除单个
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}
/**
 * 子表列表接口
 * @param params
 */
export const labSampleList = (params) =>
  defHttp.get({url: Api.labSampleList, params},{isTransformResponse:false});


  /**
 * 列表接口
 * @param params
 */
export const sampleList = (params) =>
defHttp.get({url: Api.sampleList, params});

/**
 * 样品出库
 * @param params
 */
export const sampleOut = (params) => {
  let url = Api.sampleOut;
  return defHttp.post({url: url, params});
}
/**
 * 样品回收
 * @param params
 */
export const sampleBack = (params) => {
  let url = Api.sampleBack;
  return defHttp.post({url: url, params});
}

/**
 * 样品列表接口
 * @param params
 */
export const labItemsLists = (params) =>defHttp.get({url: Api.labItemsLists, params},{isTransformResponse:false});

  /**
 * 列表接口
 * @param params
 */
  export const entrutSampleList = (params) =>defHttp.get({url: Api.entrutSampleList, params});
    
